package com.future.mayi.view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ScrollView;

import com.future.baselib.utils.CommonUtils;

public class MaxHeightScrollView extends ScrollView {
    private int maxHeight = 180;

    public MaxHeightScrollView(Context context) {
        super(context);
        init(context);
    }

    public MaxHeightScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public MaxHeightScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        maxHeight = CommonUtils.dip2px(context, maxHeight);
    }


    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        if (heightMeasureSpec > maxHeight) {
            heightMeasureSpec = maxHeight;
        }
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }


    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        if (h > maxHeight) {
            h = maxHeight;
        }

        super.onSizeChanged(w, h, oldw, oldh);

    }
}
